/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import * as types from './actionTypes';
import * as UserServices from '../services/user';

function requestLoginIn() {
    return {
      type: types.REQUEST_LOGININ
    };
}

function receiveLoginIn(userName,loginResult) {
    return {
      type: types.RECEIVE_LOGININ,
      userName,
      loginResult
    };
}

export function UserLoginIn(username,password){
    return dispatch => {
        dispatch(requestLoginIn());
        return  UserServices.UserLoginIn(username,password).then(response=>response.json())
        .then(json => {
            dispatch(receiveLoginIn(username,{result:json.result,msg:json.msg,userinfo:json.obj}));
        }).catch((error)=>{dispatch(receiveLoginIn('',{result:0,msg:'系统异常，'+error.message,userinfo:null}))})
    } 
}

export function CleanAuthrizatuon() {
   return {
    type: types.CLEAN_AUTHRIZATION
  };
}


